import os
import sys
import datetime

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_path = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
driver_path = 'E:\\python_project\\chromedriver-win64\\chromedriver.exe'


#创建浏览器对象
class Driver:
    driver=""
    def __init__(self):
        options = webdriver.ChromeOptions()
        options.binary_location = chrome_path  # 指定本地 Chrome 浏览器路径
        self.driver = webdriver.Chrome(service=Service(executable_path=driver_path), options=options)
#截屏函数
    def getScreenShot(self):
        dirname = datetime.datetime.now().strftime('%Y-%m-%d')
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S') + ".png"
        self.driver.save_screenshot(f'../images/{dirname}/' + filename)

BlogDriver=Driver()